﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class editgonggaoControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        MPPersistence Persistence1;
        TextBox txtID, txtUSERID;
        Button btnUpload;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            Persistence1 = (MPPersistence)FindControl("Persistence1");
            txtID = (TextBox)FindControl("txtID");
            txtUSERID = (TextBox)FindControl("txtUSERID");
            Panel panel1 = (Panel)FindControl("panel1");
            if (!base.Page.IsPostBack)
            {
                Persistence1.Table = "zs_gonggao";
                Persistence1.Key = "ID";
                Persistence1.KeyValue = HttpContext.Current.Request["ID"];
                Persistence1.ConnStr = _EluZSDataProvider.GetConnectionString();
            }
            Persistence1.BindControl = panel1;
            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btnSave_Click);
            Button btnUpload = (Button)FindControl("btnUpload");
            btnUpload.Click += new EventHandler(btnUpload_Click);
            isSHI();
            if (string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                btnUpload.Visible = false;
            }

        

        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {

            //设置文件上传的关键字段
            if (!string.IsNullOrEmpty(Persistence1.KeyValue))
            {
                if (true)
                {

                }
                string strScript = string.Format("<script>OpenFileUpload('{0}','{1}','{2}');</script>",
                    Persistence1.KeyValue, base.Page.Request["ID"].Trim(), base.Page.Request["ID"].Trim());
                Page.ClientScript.RegisterStartupScript(this.GetType(), "opennew", strScript);
            }
        }


        //判断是否是市征收办
        protected void  isSHI()
        {
            string sql = @"Select * From zs_role Where Id In (Select roleid From zs_user_in_role Where userid = '"+userid+@"')
And (rolename Like '%市征收%' or rolename Like '%超级管理员%')";
            DataTable dt = _EluZSDataProvider.GetTable(sql);
            Button btnUpload = (Button)FindControl("btnUpload");
            Button btn_Insert = (Button)FindControl("btn_Insert");
            if (dt.Rows.Count>0)
            {
                btn_Insert.Visible = true;
            }
            else
            {
                btn_Insert.Visible = false;
                btnUpload.Visible = false;
            }
        }



        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            txtUSERID.Text = userid;
            string strid = base.Page.Request["ID"];
            if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } else { txtID.Text = strid; }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Persistence1.Update();
            HttpContext.Current.Response.Redirect("gonggao.aspx");
        }
    }
}


